#define DEBUG
#include <cstdio>
#define MAXN 500000

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

long long max(long long a, long long b) {
  return a>b ? a : b;
}

class Point {
public:
  int x, y, id;

  static bool cmpA(Point *a, Point *b) {
    return a->x<b->x || (a->x==b->x && a->y<b->y);
  }

  static bool cmpB(Point *a, Point *b) {
    return a->x>b->x || (a->x==b->x && a->y>b->y);
  }
};

template<class T>
void sort(T *a, int l, int r, bool cmp(T *a, T *b)) {
  int i=l, j=r;
  T mid=a[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; cmp(&mid, a+j); j--);
    for (; cmp(a+i, &mid); i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, i, r, cmp);
  }
  if (j>l) {
    sort(a, l, j, cmp);
  }
}

bool check(int x, int y, Point *point, int n) {
  for (int l=1, r=n, mid; l<=r; ) {
    mid=(l+r)/2;
    if (point[mid].x<x) {
      l = mid+1;
    } else if (point[mid].x>x){
      r = mid-1;
    } else {
      if (point[mid].y<y) {
	l = mid+1;
      } else if (point[mid].y>y) {
	r = mid-1;
      } else {
	return true;
      }
    }
  }
  return false;
}

int main() {
#ifdef DEBUG
  freopen("4780.in", "r", stdin);
  freopen("4780.out", "w", stdout);
#endif

  static Point point[MAXN+1], liner[MAXN+1], linec[MAXN+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d %d", &point[i].x, &point[i].y);
    liner[point[i].y].x++;
    linec[point[i].x].x++;
  }
  for (int i=1; i<=n; i++) {
    liner[point[i].y].y+=linec[point[i].x].x-1;
    linec[point[i].x].y+=liner[point[i].y].x-1;
  }

  long long sum=0;
  for (int i=1; i<=n; i++) {
    liner[i].id=linec[i].id=i;
    sum += (liner[point[i].y].x-1)*(linec[point[i].x].x-1);
  }

  sort(point, 1, n, Point::cmpA);
  sort(liner, 1, n, Point::cmpB);
  sort(linec, 1, n, Point::cmpB);

  long long ans=0;
  int tn=min(n, 2000);
  for (int i=1; i<=tn; i++) {
    for (int j=1; j<=tn; j++) {
      if (!check(linec[i].id, liner[j].id, point, n)) {
	ans = max(ans, linec[i].x*liner[j].x+linec[i].y+liner[j].y);
      }
    }
  }
  
  printf("%lld", ans+sum);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
